<template>
<div id="content">
	<Header />
		<div class="login">
			<div class="left">
				<img src="../../../assets/img/login-bg.png" alt="">
			</div>
			<div class="right">
				<h5>帐号登录</h5>
				<div class="item">
					<img src="../../../assets/img/login-icon1.png" alt="">
					<input type="text" placeholder="请输入帐号" v-model="username">
				</div>
				<div class="item">
					<img src="../../../assets/img/login-icon2.png" alt="">
					<input type="password" placeholder="请输入密码" v-model="password" >
				</div>
				<div class="login-btn" @click="goLogin()">
					登录
				</div>
				<div class="login-icon">
					<a><router-link to="/portal/register">用户注册</router-link></a>
					<a><router-link to="/portal/forget">忘记密码？</router-link></a>
				</div>
			</div>
		</div>
		<Contact />
	</div>

</template>

<script>
import Header from '@/components/Header';
import Contact from '@/components/Contact';
import { login } from "@/api/website";
import Cookies from 'js-cookie'

export default {
	data() {
		return {
			username:"",
			password:""
		}
	},
	components: {
		Header,
		Contact
	},
	created() {
		// 在组件中访问路由参数
		if(sessionStorage.getItem("useInfo") ){
			this.$router.push('/portal/'+this.$route.query.url);
		}
	},
	methods: {
		goLogin(){
			if(!this.username){
				this.$modal.msgError("请输入帐号");
				return
			}
			if(!this.password){
				this.$modal.msgError("请输入密码");
				return
			}
			login({
				"username":this.username,
				"password":this.password
			}).then(response => {

				if(response.code == "500"){
					this.$modal.msgError(response.msg);
					return
				}
				sessionStorage.setItem("useInfo",JSON.stringify(response.data))
				// Cookies.set('Admin-Token', response.data.token);
				this.$router.push('/portal/'+this.$route.query.url);
            });
		}
	}
};
</script>

<style scoped lang="scss"></style>